package com.dji.activationDemo.messaging;

import com.dji.activationDemo.websocket.WsManager;

import dji.common.error.DJIError;
import dji.common.gimbal.Rotation;
import dji.common.gimbal.RotationMode;
import dji.common.util.CommonCallbacks;
import dji.sdk.sdkmanager.DJISDKManager;

public class GimbalRotate {
    public void rotateGimbal(String paramString,String sign) {
        String[] aa = paramString.split(",");
        float pitchVal = Float.parseFloat(aa[1]);
        float yawVal = Float.parseFloat(aa[2]);
        float rollVal = Float.parseFloat(aa[3]);

        DJISDKManager.getInstance().getProduct().getGimbal().
                rotate(new Rotation.Builder().pitch(pitchVal)
                        .mode(RotationMode.ABSOLUTE_ANGLE)
                        .yaw(yawVal)
                        .roll(rollVal)
                        .time(0)
                        .build(), new CommonCallbacks.CompletionCallback() {

                    @Override
                    public void onResult(DJIError error) {
                        if (error == null){
                            WsManager.ws.sendText("received*"+sign);
                        }else{
                            WsManager.ws.sendText("error*" + sign + "*" + error.getDescription());
                            System.out.println(error);
                        }

                    }
                });
    }

}
